<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Scrollpic_model extends CI_Model {
	
	function __construct(){
        parent::__construct();
    }
    
	/**
	 * 发布文章
	 * @param $data
	 */
	function add($data = array()){
		
		$this->mycache->delete('get_scrollpic_list_index');
		$this->db->insert('rsh_scrollpic', $data);
		return $this->db->insert_id();
	}
	

	function update($id, $data = array()){
		$this->mycache->delete('get_scrollpic_list_index');
		$this->db->where('id', $id);
		$this->db->update('rsh_scrollpic', $data);
		return $this->db->affected_rows();
	}
	
	function get_scrollpic_obj($id){
		$select = "id,url,title,pic,forder";
		$this->db->select($select);
		$this->db->where(array('id'=>$id));
		$query = $this->db->get('rsh_scrollpic');
		return $query->row_array();
	}
	
	function get_scrollpic_list(){
		//封装查询内容
		$select = "id, url, title, pic, forder";
		
		//封装条件
		$_where = " where is_del=0 ";
		$_order = " order by forder asc,id asc ";
		//封装sql
		$sql_result = "select $select from rsh_scrollpic";
		
		$sql_result .= $_where . $_order;
		$query = $this->db->query($sql_result);
		$data['scrollpic_list'] = $query->result_array();
		
		//总记录条数
		$sql_count = "select count(*) as count from rsh_scrollpic";
		$sql_count .= $_where;
		$query = $this->db->query($sql_count);
		$data['scrollpic_count'] = $query->row()->count;
		return $data;
	}

	function get_scrollpic_list_index(){
		$mkey = "get_scrollpic_list_index";
		$ret = $this->mycache->get_array($mkey);
		if($ret != false){
			return $ret;
		}
		//封装查询内容
		$select = "id, url, title, pic, forder";
		
		//封装条件
		$_where = " where is_del=0 ";
		
		$_order = " order by forder asc  ";
		//封装sql
		$sql_result = "select $select from rsh_scrollpic";
		$sql_result .= $_where . $_order;
		$query = $this->db->query($sql_result);
		$scrollpic_list = $query->result_array();
		$this->mycache->set_array($mkey,$scrollpic_list);
		return $scrollpic_list;
	}
	
	function shop_scrollpic_list(){
		
		//封装查询内容
		$select = "id, url, title, pic, forder";
		
		//封装条件
		$_where = " where is_del=0 ";
		$_order = " order by forder asc,id asc ";
		//封装sql
		$sql_result = "select $select from rsh_shop_scrollpic";
		
		$sql_result .= $_where . $_order;
		$query = $this->db->query($sql_result);
		$data['scrollpic_list'] = $query->result_array();
		
		//总记录条数
		$sql_count = "select count(*) as count from rsh_shop_scrollpic";
		$sql_count .= $_where;
		$query = $this->db->query($sql_count);
		$data['scrollpic_count'] = $query->row()->count;
		return $data;		
	}
	
	function get_shop_scrollpic_obj($id){
		$select = "id,url,title,pic,forder";
		$this->db->select($select);
		$this->db->where(array('id'=>$id));
		$query = $this->db->get('rsh_shop_scrollpic');
		return $query->row_array();
	}
	
	function add_shop_scrollpic($data){
		$this->mycache->delete('get_shop_scrollpic_list_index');
		$this->db->insert('rsh_shop_scrollpic', $data);
		return $this->db->insert_id();
	}
	
    function update_shop_scrollpic($id,$data){
    	$this->mycache->delete('get_shop_scrollpic_list_index');
		$this->db->where('id', $id);
		$this->db->update('rsh_shop_scrollpic', $data);
		return $this->db->affected_rows();
    }
    
    function get_shop_scrollpic_list_index(){
    	$mkey = "get_shop_scrollpic_list_index";
		$ret = $this->mycache->get_array($mkey);
		if($ret != false){
			return $ret;
		}
		//封装查询内容
		$select = "id, url, title, pic, forder";
		
		//封装条件
		$_where = " where is_del=0 ";
		
		$_order = " order by forder asc,id asc ";
		//封装sql
		$sql_result = "select $select from rsh_shop_scrollpic";
		$sql_result .= $_where . $_order;
		$query = $this->db->query($sql_result);
		$scrollpic_list = $query->result_array();
		$this->mycache->set_array($mkey,$scrollpic_list);
		return $scrollpic_list;
    }
	
}